package com.hayrullah.cinema.Dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;

import com.hayrullah.cinema.Util.HibernateUtil;
import com.hayrullah.cinema.entity.Saloon;

public class SaloonDao extends AbstractDao<Saloon> {

	@Override
	public Saloon findById(Long id) {

		Saloon saloon =null;
		try {
			Session session = HibernateUtil.getSessionFactory().getCurrentSession();
			session.beginTransaction();
			saloon= (Saloon)session.get(Saloon.class, id);
			session.getTransaction().commit();
		} catch (HibernateException exception) {
			exception.printStackTrace();
		}
		
		return saloon;	
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Saloon> findAll() {
	 	List<Saloon>  saloons= null;
		try {
			Session session = HibernateUtil.getSessionFactory().getCurrentSession();
			session.beginTransaction();
			saloons = (List<Saloon>) session.createCriteria(Saloon.class).list();
			session.getTransaction().commit();
		} catch (HibernateException e) {

		}
		return saloons;
	}


}
